<template lang="pug">
	.confirm-birth-info-wrap
		.card-input-container
			input-line(leftText='新生儿信息' placeholder="请选择新生儿的出生信息" type="text" :disabled='true' showArrow='true' @inputAction="selectInfo" ref="birthInfo")
			input-line(leftText='就诊手机号' placeholder="用于接收就诊短信，请认真填写" type="number" @getValue="getPhone" maxlength="11" :showBorder="false")
		.card-btn(@click="jumpToNext")
			main-button(text="确认提交" :isActive="nextStepPass")
</template>

<script>
import inputLine from '@/components/input-line'
import mainButton from '@/components/main-button'
export default {
	name: 'confirmBirthInfo',
	data() {
		return {
			name: '',
			phone: '',
			nextStepPassName: false,
			nextStepPassPhone: false
		}
	},
	computed: {
		nextStepPass() {
			return this.nextStepPassName && this.nextStepPassPhone
		}
	},
	created() {},
	mounted() {
		let that = this
		this.wx.getStorage({
			key: 'babyInfo',
			success(res) {
				let babyInfo = '',
					babyList = []
				res.data.forEach(item => {
					babyInfo = `${item.birthDate['#text']} ${item.sex['#text']} ${
						item.weight['#text']
					}克`
					babyList.push(babyInfo)
				})
				that.babyList = babyList
				console.log(that.babyList)
			}
		})
	},
	methods: {
		jumpToNext() {
			if (this.nextStepPass) {
				this.submit()
			}
		},
		getPhone(text) {
			text = text.toString()
			this.phone = text
			if (text.length === 11) {
				this.nextStepPassPhone = this.tools.isMobile(text)
			} else {
				this.nextStepPassPhone = false
			}
		},
		selectInfo() {
			let that = this
			this.wx.showActionSheet({
				itemList: that.babyList,
				success(res) {
					that.$refs.birthInfo.inputtext = that.babyList[res.tapIndex]
					that.nextStepPassName = true
				},
				fail(res) {
					console.log(res.errMsg)
				}
			})
		},
		submit() {}
	},
	components: {
		inputLine,
		mainButton
	}
}
</script>

<style lang="stylus">
	.confirm-birth-info-wrap
		.card-input-container
			margin-bottom mainMargin
			background-color white
			.input-line-wrap
				margin 0
				padding 0 40px
		.card-btn
			width 690px
			height 92px
			margin 60px auto 0
			border-radius 46px
			overflow hidden
</style>
